package com.itheima.health.service.impl;

import com.itheima.health.dao.CheckGroupItemMapper;
import com.itheima.health.dao.CheckitemMapper;
import com.itheima.health.pojo.CheckGroupItem;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.service.CheckGroupItemService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import tk.mybatis.mapper.entity.Example;

import java.util.ArrayList;
import java.util.List;

@DubboService
public class CheckGroupItemServiceImpl implements CheckGroupItemService {

    @Autowired
    private CheckGroupItemMapper checkGroupItemMapper;
    @Autowired
    private CheckitemMapper checkitemMapper;

    @Override
    public List<CheckItem> findByCheckItems(CheckGroupItem checkGroupItem) {

        Example example = new Example(CheckGroupItem.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo(checkGroupItem);
        List<CheckGroupItem> checkGroupItems = checkGroupItemMapper.selectByExample(example);

        List<CheckItem> list = new ArrayList<>();
        for (CheckGroupItem groupItem : checkGroupItems) {
            Integer checkitemId = groupItem.getCheckitemId();
            CheckItem checkItem = checkitemMapper.selectByPrimaryKey(checkitemId);
            list.add(checkItem);
        }
        return list;
    }
}
